package com.syxbyi._2threadpool;

import java.io.*;
import java.util.concurrent.locks.ReentrantLock;

public class CopyThread implements Runnable {

    private final DirectoryTree fileTree;
    private final String dest;

    public CopyThread(DirectoryTree fileTree, String dest) {
        this.fileTree = fileTree;
        this.dest = dest;
    }

    // 如果不加同步代码，会出现以下这种情况，有文件会被拷贝两次
    // Thread: 15	copy: .\data\database
    // Thread: 14	copy: .\data\database
    // Thread: 15	copy: .\data\testdir1
    // Thread: 14	copy: .\data\陈鸿宇 - 理想三旬.mp3
    // Thread: 15	copy: .\data\testdir1\testdir2
    // Thread: 14	copy: .\data\testdir1\xdl.pdf
    // Thread: 15	copy: .\data\testdir1\testdir2\video.mp4
    // Thread: 14	copy: .\data\testdir1\第一章笔记2.jpg
    @Override
    public void run() {
        while(true) {
            if (!fileTree.copyFile(dest))
                break;
        }
    }
    
}
